//
// Created by jsjxsy on 2022/8/31.
//
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
//二元谓词
class MyCompare {
 public:
  bool operator()(int num1, int num2) {
    return num1 > num2;
  }
};

bool my_compare(int a, int b) {
  return a > b;
}

void test01() {
  vector<int> v;
  v.push_back(10);
  v.push_back(40);
  v.push_back(20);
  v.push_back(30);
  v.push_back(50);

  //默认从小到大
  sort(v.begin(), v.end());
  for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
    cout << *it << " ";
  }
  cout << endl;
  cout << "----------------------------" << endl;

  //使用函数对象改变算法策略，排序从大到小
  sort(v.begin(), v.end(), MyCompare());
  for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
    cout << *it << " ";
  }
  cout << endl;
}

void test02() {
  vector<int> v;
  v.push_back(10);
  v.push_back(40);
  v.push_back(20);
  v.push_back(30);
  v.push_back(50);

  //默认从小到大
  sort(v.begin(), v.end());
  for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
    cout << *it << " ";
  }
  cout << endl;
  cout << "----------------------------" << endl;

  //使用函数对象改变算法策略，排序从大到小
  sort(v.begin(), v.end(), my_compare);
  for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  test01();
  return 0;
}

